package com.edais.axis;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.springframework.core.io.support.PropertiesLoaderUtils;

public class WebServiceUtil {
	/**webservice地址*/
	//public static String endpoint = "http://172.16.230.115:8080/message_webservice/services/DealProcessor?wsdl";// http://172.16.73.117:8080/message_webservice/services/DealProcessor?wsdl
	/**命名空间*/
	//public static String namespace = "http://websvc/";
	
	/**webservice地址*/
	public static String endpoint =  (String) WebServiceUtil.getPushSetting().get("endpoint");
	/**命名空间*/
	public static String namespace =  (String) WebServiceUtil.getPushSetting().get("namespace");

	public static Object doRequest(String no, String method, String params) {
		return doRequest(no, method, 15000, params);
	}

	/**
	 * 获取推送参数设置
	 * @return
	 * @throws IOException
	 */
	public static Map getPushSetting(){
		Map map = new HashMap();
		Properties properties = null;
		try {
			properties = PropertiesLoaderUtils.loadAllProperties("pushConfig.properties");
		} catch (IOException e) {
			e.printStackTrace();
		}
		map.put("projectNo", properties.getProperty("projectNo"));
		map.put("key", properties.getProperty("key"));
		map.put("endpoint", properties.getProperty("endpoint"));
		map.put("namespace", properties.getProperty("namespace"));
		return map;
	}
	
	/**
	 * 测试
	 * @param paras
	 */
	public static void main(String[] paras){
		Map map = getPushSetting();
		System.out.println(map);
	}
	
	/**
	 * 发送请求
	 * @param no
	 * @param method
	 * @param timeout
	 * @param params
	 * @return
	 */
	public static Object doRequest(String no, String method, int timeout, String params) {
		String resultStr = "";
		Service service = new Service();
		try {
			Call call = (Call) service.createCall();
			call.setTimeout(new Integer(timeout));
			call.setOperationName(method);//WSDL里面描述的接口名称
			call.setTargetEndpointAddress(endpoint);
			Object[] fn01 = new Object[] { no, params.toString() };
			resultStr = (String) call.invoke(namespace, method, fn01);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultStr;
	}
}
